package com.dimong.www.loan.ui.base;

import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.dimong.loan.sdk.ui.act.BaseFragmentActivity;
import com.dimong.loan.sdk.ui.frag.BaseFragment;
import com.dimong.www.loan.widget.LoanRefreshView;

/**
 * Created by wuligang on 2018/5/14.
 */

public abstract class BaseRefreshFragment extends BaseFragment implements LoanRefreshInterface {
    protected LoanRefreshView loanRefreshView;

    @Override
    public void initView() {
        if (getContainView() != null) {
            loanRefreshView = new LoanRefreshView(getActivity());
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
            params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            getContainView().addView(loanRefreshView, params);
        }
    }

    @Override
    public void showRefreshLoading() {
        showRefreshLoading(false);
    }

    @Override
    public void showRefreshLoading(boolean hasBg) {
        if (loanRefreshView != null) {
            loanRefreshView.startRefresh(hasBg);
        }
    }

    @Override
    public void showRefreshSuccess() {
        if (loanRefreshView != null) {
            loanRefreshView.stopRefresh();
        }
    }

    @Override
    public void showRefreshError() {
        if (loanRefreshView != null) {
            loanRefreshView.showNoNet("网络加载失败");
        }
    }

    @Override
    public void showNoData() {
        showNoData("没数据");
    }

    @Override
    public void showNoData(String msg) {
        if (loanRefreshView != null) {
            loanRefreshView.showNoData(msg);
        }
    }

    @Override
    public void setLoanReloadClick(LoanRefreshView.LoanReloadClick loanReloadClick) {
        if (loanRefreshView != null) {
            loanRefreshView.setLiReloadClick(loanReloadClick);
        }
    }
}
